package com.weitu.worklicense.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.worklicense.entity.RadialLicense;
import com.weitu.worklicense.mapper.RadialLicenseMapper;
import com.weitu.worklicense.service.RadialLicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/6/8.
 */
@Service
public class RadialLicenseServiceImpl implements RadialLicenseService {

    private final RadialLicenseMapper radialLicenseMapper;
    @Autowired
    public RadialLicenseServiceImpl(RadialLicenseMapper radialLicenseMapper){
        this.radialLicenseMapper=radialLicenseMapper;
    }


    @Override
    public int queryCount(Map<String, Object> map) {
        return this.radialLicenseMapper.queryCount(map);
    }

    @Override
    public List<RadialLicense> queryList(Map<String, Object> map) {
        return this.radialLicenseMapper.queryList(map);
    }

    @Override
    @Transactional
    public boolean insertRadialLicense(RadialLicense radialLicense) {
        boolean flag=false;
        int count=this.radialLicenseMapper.insertRadialLicense(radialLicense);
        if(count==1)
            flag=true;
        boolean flag2= AccessoryUtil.saveAccerssoryInfo(radialLicense.getId());
        return flag&&flag2;
    }

    @Override
    public int deleteRadialLicense(String id) {
        return this.radialLicenseMapper.deleteRadialLicense(id);
    }

    @Override
    public RadialLicense queryById(String id) {
        return this.radialLicenseMapper.queryById(id);
    }

    @Override
    @Transactional
    public boolean updateRadialLicense(RadialLicense radialLicense) {
        boolean flag=false;
        int count=this.radialLicenseMapper.updateRadialLicense(radialLicense);
        if(count==1)
            flag=true;
        boolean flag2= AccessoryUtil.saveAccerssoryInfo(radialLicense.getId());
        return flag&&flag2;
    }

    @Override
    public int execute(String id) {
        return this.radialLicenseMapper.execute(id);
    }
}
